const {
  $util,
} = getApp();
Page({
  data: {
    idx: '', // 谈话对象列表的第几个
    selectedDate: '',
    selectedTime: '',
    imgs: [],
    showPaper: false, // false 显示考试说明 true显示试卷
  },
  onLoad(opts) {
    const {
      id,
      name,
      pid,
    } = opts;
    this.setData({
      id,
      name: decodeURIComponent(name),
      pid,
    });
    this.getDesc();
  },
  getDesc() {
    $util.request({
      url: 'entry/wxapp/partylife.talk.predicttalk',
      data: {
        id: this.data.id,
      },
      success: (res) => {
        this.setData({
          list: res.data,
        });
      },
    });
  },
  startShowPaper() {
    this.setData({
      showPaper: true,
    });
  },
  /**
   *  谈话对象、选择谈话日期、谈话图片、谈话内容
   */
  bindIpVal(e) {
    const id = e.currentTarget.dataset.id;
    const m = {};
    m[id] = e.detail.value;
    this.setData(m);
  },
  /**
   * 获取最新的 待提交的图片列表
   * @param {object} e 来自组件的数据
   * @param {string[]} e.detail
   * @return
   */
  imgsOnChange(e) {
    this.setData({
      imgs: e.detail,
    });
  },
  /**
   * 提交
   */
  submit() {
    if (!this.data.selectedDate) {
      wx.showToast({
        title: '请选择谈话日期',
        icon: 'none',
      });
      return;
    }
    if (!this.data.content) {
      wx.showToast({
        title: '请填写谈话内容',
        icon: 'none',
      });
      return;
    }
    $util.request({
      url: 'entry/wxapp/partylife.talk.setdetails',
      data: {
        id: this.data.id,
        talk_time: this.data.selectedDate,
        img: this.data.imgs,
        content: this.data.content,
        pid: this.data.pid,
      },
      success: (res) => {
        wx.showToast({
          title: '提交成功',
          icon: 'none',
          duration: 1000,
          mask: true,
          success: () => {
            setTimeout(() => {
              wx.navigateBack();
            }, 1000);
          },
        });
      },
    });
  },
});
